<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>用户登录界面</title>
    </head>
    <body>
        <h3>用户登录</h3>
        <form onsubmit="return login(this)">
            <div>
                <label for="">账号</label>
                <input type="text" name="uname">
            </div>
            <div>
                <label for="">口令</label>
                <input type="password" name="upwd">
            </div>
            <div>
                <button>提交</button>
            </div>
        </form>
        <script>
            function login(_form){
                // 1、 验证数据的合法性
                // 2、发起post的Ajax请求
                let req_data = {name:_form.uname.value,pwd:_form.upwd.value};
                fetch("/cgi-bin/login",{
                    method:"POST",
                    body:JSON.stringify,
                    headers:{
                        "content-type":"application/json"
                    }
                }).then(resp=>resq.json()).then(data=>{
                    // 登录成功 {code:0,user:{id:1,nickname:"老牛", head:"/img/1.png"}}
                    // 登录失败 {cone:1,msg:"口令不存在或账号错误！"}
                    console.log(data);
                })
                return false;
            }
        </script>

    </body>
</html>